package com.yuliang.handle.exception;


import com.yuliang.domain.R;
import com.yuliang.enums.AppHttpCodeEnum;
import com.yuliang.exception.SystemException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(SystemException.class)
    public R systemExceptionHandler(SystemException e){
        log.error("出现了异常！ {SystemException}",e);//打印异常信息
        return R.errorResult(e.getCode(),e.getMessage());//从异常对象中获取提示信息封装返回
    }

    @ExceptionHandler(Exception.class)
    public R exceptionHandler(Exception e){
        log.error("出现了异常！ {Exception}",e);
        return  R.errorResult(AppHttpCodeEnum.SYSTEM_ERROR.getCode(),e.getMessage());
    }
}
